home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DBio / DSeqEd.cpp < prev    next >
Encoding:
Text File  |  1996-07-05  |  35.0 KB  |  1,396 lines  |  [TEXT/R*ch]

  1. // DSeqEd.cpp -- one sequence edit view/window 
  2. // d.g.gilbert, 1991-94 
  3.  
  4.  
  5. #include "DSeqEd.h"
  6. #include <ncbi.h>
  7. #include <dgg.h>
  8. #include <Dvibrant.h>
  9. #include <DControl.h>
  10. #include <DWindow.h>
  11. #include <DTableView.h>
  12. #include <DApplication.h>
  13. #include <DTask.h>
  14. #include <DUtil.h>
  15. #include <DDialogText.h>
  16. #include <DMenu.h>
  17. #include <DFindDlog.h>
  18.  
  19. #include "DSeqFile.h"
  20. #include "DSeqDoc.h"
  21. #include "DSeqCmds.h"
  22.  
  23.  
  24.  
  25.  
  26.  
  27. Local Nlm_FonT    gPromptFont = Nlm_programFont;
  28. //Local Nlm_FonT    gSeqFont = Nlm_programFont;
  29.  
  30. enum SeqedIDs {
  31.     mReformatHit = 2101,
  32.     ceNAM, cTEVW, ctBEG, ctEND, ctSEL, ctLEN,  ctCHK, ctTYP, cmCOD    
  33. };
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41. // class DSeqFindDialog
  42.  
  43. class DSeqFindDialog : public DFindDialog {
  44. public:
  45.     DSequence* fSequence;
  46.     DSeqedView* fSeqedView;
  47.     char    * fLastTarget;
  48.     long        fLastMatch;
  49.     DSeqFindDialog( DSequence* itsSeq, DSeqedView* itsView);
  50.     virtual void DoFind();
  51.     virtual void BuildDlog();
  52. };
  53.  
  54. DSeqFindDialog::DSeqFindDialog( DSequence* itsSeq, DSeqedView* itsView) :
  55.         fSequence(itsSeq), fSeqedView( itsView), 
  56.         fLastTarget(NULL), fLastMatch(-1)
  57. {
  58. }
  59.  
  60. void DSeqFindDialog::BuildDlog()
  61. {
  62.     DFindDialog::BuildDlog();
  63.  
  64.     DView* av;
  65.     av= FindSubview(replaceId); if (av) { av->Disable(); } //av->Hide();
  66.     av= FindSubview(replaceFindId); if (av) { av->Disable();  }
  67.     av= FindSubview(replaceAllId); if (av) { av->Disable(); }
  68.     av= FindSubview(cBackwards);     if (av) { av->Disable(); }
  69.     av= FindSubview(cFullWord); if (av) { av->Disable(); }
  70.     av= FindSubview(cCaseSense); if (av) { av->Disable(); }
  71.     if (fReplaceText) fReplaceText->Disable();
  72. }
  73.  
  74. void DSeqFindDialog::DoFind() 
  75. {
  76.     long    firstBase, nBases, match;
  77.     short n1, n2;
  78.     const char    *target;
  79.     Boolean back;
  80.     
  81.     fSequence->UpdateFlds();  
  82.     fSeqedView->GetSelection( n1, n2);
  83.     firstBase= n1;
  84.     nBases= 0; //n2 - n1;
  85.     fSequence->SetSelection( firstBase, nBases);
  86.     target= this->GetFind();
  87.     back    = this->Backwards();
  88.     if (target && *target) {
  89.         if (fLastTarget && StringCmp(target, fLastTarget)==0 && firstBase == fLastMatch)
  90.             match= fSequence->SearchAgain();
  91.         else {
  92.             if (fLastTarget) MemFree(fLastTarget);
  93.             fLastTarget= StrDup(target);
  94.             match= fSequence->Search( (char*)target, back);
  95.             }
  96.         fLastMatch= match;
  97.         if (match>=0) {
  98.             nBases= StrLen(target);
  99.             fSequence->SetSelection( match, nBases);
  100.             fSeqedView->SetSelection( match, match+nBases);
  101.             }
  102.         }
  103. }                
  104.  
  105.  
  106.  
  107.  
  108.  
  109. // DSeqedView -----------------------------
  110.  
  111.  
  112. DSeqedView::DSeqedView(long id, DView* itsSuperior, DSeqedWindow* itsDoc, DSequence* aSeq,
  113.                                  short width, short height) :
  114.     DDialogScrollText( id, itsSuperior, width, height, gSeqFont, true) // true==wrap
  115.  
  116. {
  117.   fOldStart= fOldEnd= fOldLen= -1;
  118.     fOldKind= -1; 
  119.     fOldCheck= -1;
  120.  
  121.     //fControlChars = fControlChars - [chTab];
  122.     
  123.     Nlm_RecT         arect; 
  124.     Nlm_LoadRect(&arect,0,0,0,0);
  125.     fOldDest= arect;
  126.     fOldView= arect;
  127.     fChanged= FALSE;
  128.  
  129.     // FailNIL( aSeq); 
  130.     if (!aSeq) { delete this; return; }
  131.     fSequence= aSeq;
  132.     fDoc= itsDoc;
  133.  
  134.   fSeqStart = fDoc->fSeqStart;
  135.   fSeqEnd = fDoc->fSeqEnd;
  136.   fSeqSel = fDoc->fSeqSel;
  137.   fSeqLen = fDoc->fSeqLen;
  138.   fSeqCheck = fDoc->fSeqCheck;
  139.   //fSeqTyp = fDoc->fSeqTyp;
  140.   fCodePop = fDoc->fCodePop;
  141.   fCodePop->SetValue( fSequence->Kind());
  142.  
  143.     //SetKeyHandler(this); //?? also need this call in a window activate/deactivate method??
  144.  
  145.     this->SetResize( DView::relsuper, DView::relsuper);
  146.     this->SetText( fSequence->Bases());
  147.  
  148.     UpdateCtls(TRUE); //??
  149. }
  150.  
  151.  
  152. DSeqedView::~DSeqedView()
  153. {
  154.     if (fChanged && fDoc && fDoc->fMainDoc)    
  155.         fDoc->fMainDoc->Dirty(); //((DSeqDoc*)fSuperior)->Dirty();
  156. }
  157.  
  158.  
  159. void DSeqedView::SetSeq(DSequence* aSeq) 
  160. {
  161.     fSequence= aSeq;
  162.     this->SetText( fSequence->Bases());
  163.     UpdateCtls(true);
  164.     //this->Invalidate(); //??
  165. }
  166.  
  167. void DSeqedView::UpdateCtls(Boolean forceIndex)  //call this when seq indices change
  168. {    
  169.      char    newNum[256];
  170.      short    n1, n2;
  171.     Boolean        newrange, didChange;
  172.     Nlm_RecT        adest, aview, bview;
  173.      
  174.      
  175.     newrange= FALSE;    
  176.     didChange= FALSE;
  177.     adest= fOldDest;
  178.     aview= fOldView;
  179.     this->ViewRect(bview);
  180.     
  181. #if 0
  182.     if (!Nlm_EqualRect( &aview, &bview)) fSeqHindex->Invalidate();  
  183.         
  184.     if (forceIndex 
  185.      || !Nlm_EqualRect(&adest, (*fHTE)->destRect) 
  186.      || !Nlm_EqualRect(&aview, &bview)) {
  187.         fSeqIndex->Invalidate();  
  188.         fOldDest= (*fHTE)->destRect;
  189.         fOldView= bview;
  190.         }
  191. #endif         
  192.         
  193.     this->GetSelection( n1, n2);
  194.     if (n1 != fOldStart) {
  195.         sprintf(newNum, "%d", n1+1);
  196.         fSeqStart->SetTitle(newNum);
  197.         fOldStart= n1;
  198.         newrange= TRUE;
  199.         }
  200.     
  201.     if (n2 != fOldEnd) {
  202.         short val;
  203.         if (n2 > n1) val= n2; else val= n2+1;
  204.         sprintf(newNum, "%d", val);
  205.         fSeqEnd->SetTitle(newNum);
  206.         fOldEnd= n2;
  207.         newrange= TRUE;
  208.         }
  209.  
  210.     if (newrange) {
  211.         sprintf(newNum, "%d", n2 - n1);
  212.         fSeqSel->SetTitle(newNum);
  213.         }
  214.  
  215.     if (fSequence->Checksum() != fOldCheck) {
  216.         sprintf(newNum, "%-8lx", fSequence->Checksum());
  217.         fSeqCheck->SetTitle(newNum);
  218.         fOldCheck= fSequence->Checksum();
  219.         didChange= TRUE;
  220.         }
  221.         
  222.     if (fSequence->Kind() != fOldKind) {
  223.       fCodePop->SetValue( fSequence->Kind()+1);         
  224.         //fSequence->SetKind(fCodePop->GetValue()-1); 
  225.         fOldKind= fSequence->Kind();
  226.         didChange= TRUE;
  227.         }
  228.         
  229.     long len= this->TextLength();
  230.     if (len != fOldLen) {
  231.         sprintf(newNum, "%d", len);
  232.         fSeqLen->SetTitle(newNum);
  233.         //fSeqIndex->AdjustFrame(); //! change index size, ?do this only when nlines changes?
  234.         fOldLen= len;
  235.         didChange= TRUE;
  236.         }
  237.         
  238.     if (didChange) this->fChanged= TRUE;
  239. }
  240.  
  241.  
  242.  
  243. //-- Override some TTEView routines that can change selection && scroll
  244. // SynchView is called only/just after some, but not all, RecalcTexts 
  245. // main usage will be from Resize 
  246.  
  247. void DSeqedView::selectAction()
  248. {
  249.     DDialogScrollText::selectAction();
  250.     gCursor->ibeam();
  251.     SetKeyHandler(this); //?? also need this call in a window activate/deactivate method??
  252.     this->UpdateCtls(TRUE);
  253. }
  254.  
  255. void DSeqedView::deselectAction()
  256. {
  257.     SetKeyHandler(NULL); //?? also need this call in a window activate/deactivate method??
  258.     fDoc->SetEditText(NULL);
  259.     gCursor->arrow();
  260.     DDialogScrollText::deselectAction();
  261. }
  262.  
  263.  
  264. /****
  265. class DKeyCallback
  266. {
  267. public:
  268.     DKeyCallback();
  269.     virtual ~DKeyCallback();
  270.     virtual void SetKeyHandler(DKeyCallback* handler);
  271.   virtual void ProcessKey( char c) = 0;
  272. };
  273. *****/
  274.  
  275. void DSeqedView::ProcessKey( char c)
  276. {
  277.     //fSequence->SetKind(fCodePop->GetValue()-1); //?? why this on each char?? 
  278.     if ( IsEnabled()) { 
  279.             if (!fSequence->GoodChar(c)) {
  280.                 Nlm_Beep(); //gApplication->Beep(1);  
  281.                 // Flush further keystrokes ?
  282.                 }
  283.         UpdateCtls(FALSE);
  284.         }
  285. }
  286.  
  287.  
  288.  
  289.  
  290.  
  291. Boolean DSeqedView::DoMenuTask(long tasknum, DTask* theTask)
  292. {
  293.     DWindow* win = NULL;
  294.     
  295.     switch (tasknum) {
  296.  
  297.         case DSeqDoc::cFindORF:
  298.             {
  299.                 long    start, stop;
  300.                 short n1, n2;
  301.                 
  302.                 fSequence->UpdateFlds();  
  303.                 this->GetSelection( n1, n2);
  304.                 if (n2 > n1+1) n1++; // !? offset sel start so we can repeat call
  305.                 fSequence->SetSelection( n1, 0);
  306.                 fSequence->SearchORF( start, stop);
  307.                 if (start>=0) {
  308.                     if (stop<start) stop= fSequence->LengthF(); //??
  309.                     fSequence->SetSelection( start, stop - start);
  310.                     this->SetSelection( start, stop);
  311.                     }
  312.             }                
  313.             return true;
  314.  
  315.         case DSeqDoc::cRevSeq:
  316.         case DSeqDoc::cCompSeq:
  317.         case DSeqDoc::cRevCompSeq:
  318.         case DSeqDoc::cDna2Rna: 
  319.         case DSeqDoc::cRna2Dna:
  320.         case DSeqDoc::cToUpper: 
  321.         case DSeqDoc::cToLower:
  322.         case DSeqDoc::cDegap:
  323.         case DSeqDoc::cLockIndels:
  324.         case DSeqDoc::cUnlockIndels:
  325.         //case DSeqDoc::cConsensus:
  326.         case DSeqDoc::cTranslate:
  327.             {
  328.             long    firstBase, nBases;
  329.             short n1, n2;
  330.             DSeqList * aSeqList= NULL;
  331.             DSeqChangeCmd *    cmd = NULL;  
  332.             DSeqDoc* maindoc= this->fDoc->fMainDoc;
  333.             
  334.             //GetSelection( TRUE, TRUE, aSeqList, firstBase, nBases);
  335.             fSequence->UpdateFlds();  
  336.             this->GetSelection( n1, n2);
  337.             firstBase= n1;
  338.             nBases= n2 - n1;
  339.             fSequence->SetSelection( firstBase, nBases);
  340.             aSeqList= new DSeqList();
  341.             aSeqList->InsertLast(fSequence);
  342.             
  343.             switch (tasknum) {
  344.               case DSeqDoc::cRevSeq            : cmd= new DSeqReverseCmd( maindoc, this, aSeqList);  break;
  345.                 case DSeqDoc::cCompSeq        : cmd= new DSeqComplementCmd(  maindoc, this, aSeqList); break;
  346.                 case DSeqDoc::cRevCompSeq : cmd= new DSeqRevComplCmd(  maindoc, this, aSeqList); break;
  347.                 case DSeqDoc::cDna2Rna        : cmd= new DSeqDna2RnaCmd(  maindoc, this, aSeqList); break;
  348.                 case DSeqDoc::cRna2Dna        :    cmd= new DSeqRna2DnaCmd(  maindoc, this, aSeqList); break;
  349.                 case DSeqDoc::cToUpper        :    cmd= new DSeqUppercaseCmd(  maindoc, this, aSeqList); break;
  350.                 case DSeqDoc::cToLower        :    cmd= new DSeqLowercaseCmd(  maindoc, this, aSeqList); break;
  351.                 case DSeqDoc::cDegap            :    cmd= new DSeqCompressCmd(  maindoc, this, aSeqList); break;
  352.                 case DSeqDoc::cLockIndels    :    cmd= new DSeqLockIndelsCmd( maindoc, this, aSeqList); break;
  353.                 case DSeqDoc::cUnlockIndels: cmd= new DSeqUnlockIndelsCmd( maindoc, this, aSeqList); break;
  354.                 case DSeqDoc::cTranslate    :    cmd= new DSeqTranslateCmd( maindoc, this, aSeqList); break;
  355.                 
  356.                 default:
  357.                     delete aSeqList;
  358.                     Message(MSG_OK,"DSeqedView::method not ready.");
  359.                     return true;
  360.                 
  361.               }
  362.           if (cmd) {
  363.               if (cmd->Initialize()) PostTask( cmd);
  364.               else {
  365.                   delete cmd;
  366.                   Message(MSG_OK,"DSeqedView::method failed.");
  367.                     }
  368.               }
  369.             return true;    
  370.             }
  371.         
  372.         case DSeqDoc::cPrettyPrint:  //MakeAlnPrint();
  373.         case DSeqDoc::cREMap:                //MakeSeqPrint( TRUE); 
  374.         case DSeqDoc::cDotPlot:            //MakeDottyPlot();
  375.             Message(MSG_OK,"DSeqedView::method not ready.");
  376.             return true;
  377.  
  378.         default: 
  379.             return DTaskMaster::DoMenuTask(tasknum, theTask);
  380.         }
  381.  
  382. }
  383.  
  384.  
  385. Boolean DSeqedView::IsMyAction(DTaskMaster* action) 
  386. {
  387.     long  menuid= 0;
  388.     if (action->fSuperior)  menuid = action->fSuperior->Id();
  389.     switch(action->Id()) {
  390.         case DApplication::kCut:
  391.         case DApplication::kCopy:
  392.         case DApplication::kPaste:
  393.         case DApplication::kClear:
  394.         case DApplication::kSelectAll:
  395.             return DDialogText::IsMyAction(action);
  396.         }
  397.         
  398.     return DoMenuTask(action->Id(), NULL);
  399. }
  400.             
  401.  
  402.  
  403.  
  404.  
  405.  
  406. // TSeqIndex ----------------------------------
  407.  
  408.  
  409. #if FIX_LATER
  410.  
  411. pascal void TSeqIndex::Initialize(void) // override 
  412. {
  413.     inherited::Initialize();
  414.     fTEView    = NULL;
  415. }
  416.  
  417. pascal void TSeqIndex::CalcMinFrame(VRect VAR minFrame) // override 
  418. // THIS WAS bombing us on initial call to CreateViews.. until we IRes'd
  419. VAR
  420.     VRect        superExtent;
  421. {
  422.   inherited::CalcMinFrame(minFrame);
  423.     if (fSuperView!=NULL) {
  424.         fSuperView->GetExtent(superExtent);
  425.         minFrame.bottom= max(minFrame.bottom, superExtent.bottom);
  426.         }
  427.     if ((fTEView!=NULL) && (fTEView->fHTE!=NULL))
  428.         minFrame.bottom= max(minFrame.bottom, 10+TEGetHeight(0,fTEView.(*fHTE)->nlines,fTEView->fHTE));
  429. }
  430.  
  431. pascal void TSeqIndex::Draw(VRect area) // override 
  432. VAR
  433.     rect        vrect ;
  434.     integer        cat, il, h, v, v1, nl, vend, ih, ws ;
  435.     nums    : Str255;
  436.     ptop    : point;
  437. {
  438.     if ((fTEView!=NULL)) {
  439.         vrect= fTEView.(*fHTE)->viewrect;
  440.         h        = area.right-3;
  441.         v        = vrect.top;
  442.         vend= area.bottom;
  443.         
  444.         cat = TEGetOffset(vrect.topleft,fTEView->fHTE);
  445.         il  = 0;
  446.         nl= fTEView.(*fHTE)->nlines;
  447.         while ( (il < nl) && (cat > fTEView.(*fHTE)->lineStarts[il]) do il= il+1;
  448.         while ( (v < vend) && (il < nl)){
  449.             v1= v + TEGetHeight( il, il, fTEView->fHTE);
  450.             if ((v1 >= area.top) && (v <= vend)) {
  451.                 cat= fTEView.(*fHTE)->lineStarts[il];
  452.                 NumToString( cat, nums);
  453.                 moveto( h-StringWidth(nums), v1);
  454.                 drawString(nums); 
  455.                 }
  456.             v= v1;  
  457.             il= il + 1;
  458.             }
  459.         }
  460.     inherited::Draw(area); //!?
  461. }
  462.  
  463. #endif //FIX_LATER
  464.  
  465.  
  466.  
  467.  
  468. // TSeqHIndex ----------------------------
  469.  
  470. #if FIX_LATER
  471.  
  472. pascal void TSeqHIndex::Draw(VRect area) // override 
  473. var
  474.     rect        vrect ;
  475.     integer        cat, ecat, il, h, v, vend, ws ;
  476.     nums    : Str255;
  477.     pt        : point;
  478. {
  479.     if ((fTEView!=NULL)) {
  480.         vrect= fTEView.(*fHTE)->viewrect;
  481.         v        = area.bottom;
  482.         vend= area.right;
  483.         cat = TEGetOffset(vrect.topleft,fTEView->fHTE); //!? is pt rel to view or dest ?
  484.     
  485.         WITH fTEView.(*fHTE)^){
  486.             il  = 0;
  487.             while ( (il < nlines) && (cat >= lineStarts[il]))il= il+1;
  488.             ecat= lineStarts[il];
  489.             if (il>0) cat= lineStarts[il-1];
  490.             }
  491.         
  492.         il= 5; 
  493.         cat= cat + 4; //? skip 1
  494.         do {
  495.             pt= TEGetPoint(cat, fTEView->fHTE);
  496.             moveto(pt.h, v);
  497.     
  498.             if ((il mod 10 == 0)) {
  499.                 line(0,-3);
  500.                 NumToString( il, nums);
  501.                 ws= StringWidth(nums);
  502.                 move(-ws div 2,-1);
  503.                 drawstring(nums);
  504.                 }            else 
  505.                 line(0,-8);
  506.             cat= cat + 5;
  507.             il= il+5;
  508.         } while (!((pt)).h >= area.right) || (cat >= ecat);
  509.         }
  510.     inherited::Draw(area);
  511. }
  512.  
  513.  
  514. #endif //FIX_LATER
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522. // DSeqedWindow ------------------------
  523.  
  524.  
  525.  
  526.     
  527. DSeqedWindow::DSeqedWindow(long id, DTaskMaster* itsSuperior, DSeqDoc* itsSeqDoc, DSequence* aSeq,
  528.                                     short winwidth, short winheight, short winleft, short wintop, char* title) :
  529.     DWindow(id, itsSuperior, DWindow::document, winwidth, winheight, winleft, wintop, title)
  530. {    
  531.     DView* super = this;
  532.     DPrompt* pr;
  533.     DCluster* clu;
  534.     
  535.         // fix this later...
  536.     gPromptFont= Nlm_programFont;
  537.     //gSeqFont     = Nlm_programFont;
  538.  
  539.     fSequence= aSeq; // ?? Clone it for safety ??
  540.     fMainDoc= itsSeqDoc;
  541.     
  542.   clu= new DCluster(0,super,0,0,true,NULL);
  543.   super= clu;
  544.   pr = new DPrompt(0, super, "Name:", 0, 0, gPromptFont, justleft);
  545.   super->NextSubviewToRight();
  546.   fSeqName = new DEditText( ceNAM, super, aSeq->Name(), 20);  
  547.   
  548.  
  549.     super= this;
  550.     super->NextSubviewBelowLeft();
  551.     
  552.   clu= new DCluster(0,super,0,0,false,"Sequence");
  553.     super= clu;
  554.         
  555.   pr = new DPrompt(0, super, " length:", 0, 0, gPromptFont, justleft);
  556.   super->NextSubviewToRight();
  557.      fSeqLen = new DPrompt(ctLEN, super, "00000", 0, 0, gPromptFont, justright);
  558.   super->NextSubviewToRight();
  559.   
  560.   pr = new DPrompt(0, super, " checksum:", 0, 0, gPromptFont, justleft);
  561.   super->NextSubviewToRight();
  562.   fSeqCheck = new DPrompt(ctCHK, super, "0000000", 0, 0, gPromptFont, justright);
  563.   super->NextSubviewToRight();
  564.   
  565.   pr = new DPrompt(0, super, " type:", 0, 0, gPromptFont, justleft);
  566.   super->NextSubviewToRight();
  567.   //fSeqTyp   = new DPrompt(ctTYP, super, "Unknown type", 0, 0, gPromptFont, justleft);
  568.   //super->NextSubviewToRight();
  569.   fCodePop  = new DPopupList( cmCOD, super, true);
  570.   fCodePop->AddItem("Unknown type");
  571.   fCodePop->AddItem("DNA");
  572.   fCodePop->AddItem("RNA");
  573.   fCodePop->AddItem("Nucleic");
  574.   fCodePop->AddItem("Protein");
  575.   fCodePop->SetValue( fSequence->Kind()+1); // ?? damn this doesn't work 
  576.     //fSequence->SetKind(fCodePop->GetValue()-1); 
  577.  
  578.  
  579.     super= this;
  580.     super->NextSubviewBelowLeft();
  581.     
  582.   clu= new DCluster(0,super,0,0,false,"Selection");
  583.   super= clu;
  584.   pr = new DPrompt(0, super, "start:", 0, 0, gPromptFont, justleft);
  585.   super->NextSubviewToRight();
  586.   fSeqStart = new DPrompt(ctBEG, super, "00000", 0, 0, gPromptFont, justright);
  587.   super->NextSubviewToRight();
  588.  
  589.   pr = new DPrompt(0, super, " end:", 0, 0, gPromptFont, justleft);
  590.   super->NextSubviewToRight();
  591.   fSeqEnd   = new DPrompt(ctEND, super, "00000", 0, 0, gPromptFont, justright);
  592.   super->NextSubviewToRight();
  593.  
  594.   pr = new DPrompt(0, super, " size:", 0, 0, gPromptFont, justleft);
  595.   super->NextSubviewToRight();
  596.   fSeqSel   = new DPrompt(ctSEL, super, "00000", 0, 0, gPromptFont, justright);
  597.       
  598.  
  599.     super= this;
  600.     super->NextSubviewBelowLeft();
  601.      
  602.     fSeqedView= new DSeqedView(cTEVW, super, this, fSequence, 30, 8); // sizes are in SysFontSize...
  603.     fSeqedView->Enable(); //??
  604.     this->SetEditText(fSeqedView);
  605.  
  606.     fFindDlog= new DSeqFindDialog( fSequence, fSeqedView);
  607. }
  608.  
  609. DSeqedWindow::~DSeqedWindow()
  610. {
  611.     // ?? do we need to kill the view components, or does window free do that??
  612. }
  613.  
  614.  
  615. // static
  616. void DSeqedWindow::UpdateEdWinds( DSequence* oldSeq, DSequence* newSeq)
  617. {
  618.     DList* wins= gWindowManager->GetWindowList();
  619.     long i, n= wins->GetSize();
  620.     for (i=0; i<n; i++) {
  621.         DWindow* win= (DWindow*) wins->At(i);
  622.         if (win->Id() == DSeqedWindow::kId) {
  623.             if (((DSeqedWindow*)win)->fSequence == oldSeq) {
  624.                 ((DSeqedWindow*)win)->ReplaceSeq(newSeq);
  625.                 win->Invalidate();
  626.                 }
  627.             }
  628.         }
  629. }
  630.  
  631.                 
  632. #if MAYBE_FIX_LATER
  633. pascal void TSeqedWindow::DoEvent(EventNumber eventNumber, 
  634.                                             TEventHandler        source; TEvent event) // override 
  635. {
  636.     if (eventNumber == mReformatHit) {
  637.         fSequence->Reformat(1);
  638.         fSeqedView->ShowReverted(); //? calls recalc + display?
  639.         }    else
  640.         inherited::DoEvent( eventNumber, source, event);
  641. }
  642. #endif        
  643.  
  644.  
  645. Nlm_Boolean DSeqedWindow::IsMyAction(DTaskMaster* action) 
  646. {    
  647.     long  menuid= 0;
  648.     if (action->fSuperior) menuid = action->fSuperior->Id();
  649.     if (fSeqedView->IsMyAction(action)) 
  650.         return true;
  651.     else if (menuid == DApplication::cEditMenu && HasEditText()) {
  652.         if (fEditText->IsMyAction(action)) ;
  653.         return true;
  654.         }        
  655.     else 
  656.         return DWindow::IsMyAction(action);
  657. }
  658.  
  659.  
  660. void DSeqedWindow::UpdateEdits() 
  661. {
  662.     char    name[128];
  663.     fSeqName->GetTitle( name, 128);
  664.     fSequence->SetName( name);
  665.     
  666.     char* bases= fSeqedView->GetText();
  667.     if (bases) fSequence->SetBases(bases);
  668.     MemFree(bases);
  669.     
  670.     fSequence->UpdateFlds();
  671.     
  672.         //! Need better way than to ForceRedraw of single seq...
  673.     if (fMainDoc) {
  674.         fMainDoc->fAlnView->UpdateWidth(fSequence);
  675.         fMainDoc->fAlnView->Invalidate(); 
  676.         fMainDoc->fAlnIndex->Invalidate();
  677.         }
  678. }
  679.  
  680.  
  681. void DSeqedWindow::Close()  
  682. {
  683.     UpdateEdits();
  684.   DWindow::Close();
  685. }
  686.  
  687.  
  688. void DSeqedWindow::ReplaceSeq(DSequence* aSeq)
  689. {    
  690.     fSequence= aSeq;
  691.     fSeqedView->SetSeq( aSeq);
  692. }
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709. //class DSeqDocPrefs : public DWindow 
  710.  
  711. class DSeqDocPrefs : public DWindow {
  712. public:
  713.     enum { 
  714.             kSeqDocPrefID = 1492,
  715.             kStylePlain,kStyleItalic,kStyleBold,kStyleUnderline,
  716.             cWriteMasks, cStartDoc, cColored,
  717.             cDistCor, cMatKind
  718.             };
  719.     static char *gSeqFontName;
  720.     static short gSeqFontSize;
  721.     static short gSeqStyle;
  722.     static Boolean gColored;
  723.     static void InitGlobals();
  724.     static void SaveGlobals();
  725.  
  726.     DPopupMenu  * fSeqFontMenu, 
  727.                             * fSeqStyleMenu;
  728.     DSwitchBox    * fSeqSizeSw, * fCommonPctSw, * fMinORFSw;
  729.     Boolean             fNeedSave;
  730.     short                fOldStyle;
  731.     DCluster    * fDistCor, * fMatKind;
  732.     
  733.     DSeqDocPrefs();
  734.     virtual ~DSeqDocPrefs();
  735.     virtual void Initialize();
  736.     virtual void Open();
  737.     virtual void Close();
  738.     virtual void OkayAction();
  739.     virtual Boolean IsMyAction(DTaskMaster* action); 
  740.     virtual void NewFontCluster(char* title, DView* mainview,
  741.                     DPopupMenu*& mfont, DPopupMenu*& mstyle, DSwitchBox*& swsize,
  742.                     char* fontname, short fontstyle, short fontsize );
  743. };
  744.  
  745. Global DSeqDocPrefs* gSeqDocPrefs = NULL;
  746. Global Nlm_FonT gSeqFont = NULL;
  747.  
  748. char* DSeqDocPrefs::gSeqFontName = (char*) "times";
  749. short 
  750.             DSeqDocPrefs::gSeqFontSize = 10, 
  751.             DSeqDocPrefs::gSeqStyle = 0; 
  752. Boolean     
  753.             DSeqDocPrefs::gColored = true;
  754.  
  755. enum FonStyles { 
  756.     kPlain = 0, kItalic = 1, kBold = 2, kUnderline = 4 
  757.     };
  758.  
  759.  
  760. DSeqDocPrefs::DSeqDocPrefs() :
  761.     DWindow( 0, NULL, DWindow::fixed, -10, -10, -50, -20, "SeqDoc prefs", kDontFreeOnClose),
  762.     fSeqFontMenu(NULL), fSeqStyleMenu(NULL), fSeqSizeSw(NULL), fCommonPctSw(NULL),
  763.     fMinORFSw(NULL),
  764.     fDistCor(NULL), fMatKind(NULL),
  765.     fOldStyle(-1), fNeedSave(false)
  766. {    
  767. }
  768.  
  769. DSeqDocPrefs::~DSeqDocPrefs()
  770. {
  771. }
  772.  
  773.  
  774. inline Nlm_FonT GetAFont( char* fname, short fsize, short fstyle)
  775. {
  776.     if (StrICmp(fname,"System")==0) return Nlm_systemFont;
  777.     else if (StrICmp(fname,"Program")==0) return Nlm_programFont;
  778.     else return Nlm_GetFont( fname, fsize, 
  779.              fstyle & kBold, fstyle & kItalic, fstyle & kUnderline, NULL);
  780. }
  781.  
  782. // static
  783. void DSeqDocPrefs::InitGlobals() 
  784.     gSeqFontName= gApplication->GetPref( "gSeqFontName", "fonts", gSeqFontName);
  785.     gSeqFontSize= gApplication->GetPrefVal( "gSeqFontSize", "fonts", "10");
  786.     gSeqStyle= gApplication->GetPrefVal( "gSeqStyle", "fonts", "0");
  787.     gSeqFont= ::GetAFont(gSeqFontName,gSeqFontSize, gSeqStyle);
  788.  
  789.     DSeqFile::gWriteMasks= gApplication->GetPrefVal( "gWriteMasks", "seqdoc", "1");
  790.     DSeqDoc::fgStartDoc    = gApplication->GetPrefVal( "fgStartDoc", "seqdoc", "1");
  791.     DSeqList::gMinCommonPercent= gApplication->GetPrefVal( "gMinCommonPercent", "seqdoc", "70");
  792.     DSeqList::gMinORFsize= gApplication->GetPrefVal( "gMinORFsize", "seqdoc", "20");
  793.  
  794.     DSeqDoc::fgDistCor    = gApplication->GetPrefVal( "fgDistCor", "seqdoc", "0");
  795.     DSeqDoc::fgMatKind    = gApplication->GetPrefVal( "fgMatKind", "seqdoc", "0");
  796.  
  797.     //gColored= gApplication->GetPrefVal( "gColored", "seqdoc","1");
  798. #if 0
  799.     {
  800.     char* srect = gApplication->GetPref( "gSeqPrintDocRect", "windows", "20 20 450 220");
  801.         // sscanf is failing on Mac/codewar !? used to work
  802.     if (srect) {
  803.         char* cp= srect;
  804.         while (*cp && isspace(*cp)) cp++;
  805.         gSeqPrintDocRect.left= atoi( cp);
  806.         
  807.         while (*cp && !isspace(*cp)) cp++;
  808.         while (*cp && isspace(*cp)) cp++;
  809.         gSeqPrintDocRect.top= atoi( cp);
  810.         
  811.         while (*cp && !isspace(*cp)) cp++;
  812.         while (*cp && isspace(*cp)) cp++;
  813.         gSeqPrintDocRect.right= atoi( cp);
  814.         
  815.         while (*cp && !isspace(*cp)) cp++;
  816.         while (*cp && isspace(*cp)) cp++;
  817.         gSeqPrintDocRect.bottom= atoi( cp);
  818.         }
  819.     MemFree(srect);
  820.     }    
  821. #endif
  822.  
  823. }
  824.  
  825.  
  826. //static
  827. void DSeqDocPrefs::SaveGlobals() 
  828. {
  829.     gApplication->SetPref( gSeqFontName, "gSeqFontName", "fonts");
  830.     gApplication->SetPref( gSeqFontSize, "gSeqFontSize", "fonts");
  831.     gApplication->SetPref( gSeqStyle, "gSeqStyle", "fonts");
  832.     
  833.     //gApplication->SetPref( gColored, "gColored", "seqdoc");
  834.     gApplication->SetPref(  DSeqFile::gWriteMasks, "gWriteMasks", "seqdoc");
  835.     gApplication->SetPref(  DSeqDoc::fgStartDoc, "fgStartDoc", "seqdoc");
  836.     gApplication->SetPref(  DSeqDoc::fgDistCor, "fgDistCor", "seqdoc");
  837.     gApplication->SetPref(  DSeqDoc::fgMatKind, "fgMatKind", "seqdoc");
  838.     gApplication->SetPref(  DSeqList::gMinCommonPercent, "gMinCommonPercent", "seqdoc");
  839.     gApplication->SetPref(  DSeqList::gMinORFsize, "gMinORFsize", "seqdoc");
  840.  
  841. }
  842.  
  843.  
  844.  
  845.  
  846. void DSeqDocPrefs::NewFontCluster(char* title, DView* mainview,
  847.                     DPopupMenu*& mfont, DPopupMenu*& mstyle, DSwitchBox*& swsize,
  848.                     char* fontname, short fontstyle, short fontsize )
  849. {    
  850.         // Name style -- font, font size, font style
  851.     DPopupMenu* popm;
  852.     DSwitchBox* sw;
  853.     DPrompt* pr;
  854.     DView* super;
  855.     
  856.     super= mainview;
  857.     super->NextSubviewBelowLeft();
  858.  
  859.     DCluster* maincluster= new DCluster( 0, super, 50, 10, true, NULL); //false, title);
  860.     super= maincluster;
  861.  
  862.     popm= new DPopupMenu( 0, (Nlm_GrouP)super->GetNlmObject(), "Font  ");
  863.     mfont= popm;
  864.     popm->AddFonts();
  865.     popm->SetFontChoice( fontname); 
  866.     //super->NextSubviewToRight();
  867.  
  868. #if 0
  869.     DPopupList* popl;
  870.     popl= new DPopupList( 0,super,true);
  871.     mstyle= (DPopupMenu*) popl;
  872.     popl->AddItem("Plain");
  873.     popl->AddItem("Italic");
  874.     popl->AddItem("Bold");
  875.     popl->AddItem( "Underline");
  876. #else
  877.     popm= new DPopupMenu( 0, (Nlm_GrouP)super->GetNlmObject(), "Style  ");
  878.     mstyle= popm;
  879.     popm->AddItem( kStylePlain, "Plain", true);
  880.     popm->AddItem( kStyleItalic, "Italic", true);
  881.     popm->AddItem( kStyleBold, "Bold", true);
  882.     popm->AddItem( kStyleUnderline, "Underline", true);
  883.     popm->SetItemStatus( kStylePlain, fontstyle==0);
  884.     popm->SetItemStatus( kStyleItalic, fontstyle & kItalic);
  885.     popm->SetItemStatus( kStyleBold, fontstyle & kBold);
  886.     popm->SetItemStatus( kStyleUnderline, fontstyle & kUnderline);
  887. #endif
  888.     //super->NextSubviewToRight();
  889.     
  890.     DCluster* cluster= new DCluster(0, super, 30, 10, true, NULL);
  891.     super= cluster;
  892.     
  893.     pr= new DPrompt( 0, super, "font size", 0, 0, Nlm_programFont);             
  894.     //super->NextSubviewToRight();
  895.     super->NextSubviewBelowLeft();
  896.     sw = new DSwitchBox(0, super, true, true);
  897.     swsize= sw;
  898.     sw->SetValues(fontsize,99);
  899.     //super->NextSubviewBelowLeft();
  900.  
  901.     super= mainview;
  902.     super->NextSubviewBelowLeft();
  903. }
  904.  
  905.  
  906. void DSeqDocPrefs::Initialize() 
  907.     DView* super;
  908.     DCluster* clu;
  909.     DCheckBox* ck;
  910.     DRadioButton* rad;
  911.  
  912.     super= this;
  913.     clu= new DCluster( 0, super, 80, 10, false, "Sequence");
  914.     super= clu;
  915.  
  916.     NewFontCluster( "Seq font style", super, fSeqFontMenu, fSeqStyleMenu, fSeqSizeSw,
  917.                             gSeqFontName, gSeqStyle, gSeqFontSize);
  918.   fOldStyle= gSeqStyle;
  919.  
  920.     super= this;
  921.     ck= new DCheckBox(cWriteMasks, super, "Save masks in file");
  922.     ck->SetStatus(DSeqFile::gWriteMasks);
  923.     super->NextSubviewBelowLeft();
  924.  
  925.     // check box for auto new document on startup ??
  926.     ck= new DCheckBox(cStartDoc, super, "New align document on startup");
  927.     ck->SetStatus(DSeqDoc::fgStartDoc);
  928.     super->NextSubviewBelowLeft();
  929.  
  930.     new DPrompt( 0, super, "% common bases for consensus", 0, 0, Nlm_programFont);             
  931.     super->NextSubviewToRight();
  932.     fCommonPctSw = new DSwitchBox(0, super, true, true);
  933.     fCommonPctSw->SetValues(DSeqList::gMinCommonPercent,100);
  934.     super->NextSubviewBelowLeft();
  935.     
  936.     new DPrompt( 0, super, "Minimum ORF size", 0, 0, Nlm_programFont);             
  937.     super->NextSubviewToRight();
  938.     fMinORFSw = new DSwitchBox(0, super, true, true);
  939.     fMinORFSw->SetValues(DSeqList::gMinORFsize,200);
  940.     super->NextSubviewBelowLeft();
  941.  
  942.     //ck= new DCheckBox(cColored, super, "Colored bases");
  943.     //ck->SetStatus(gColored);
  944.  
  945.     super = this;
  946.     fMatKind= new DCluster(cMatKind,super,0,0,false,"Comparison matrix");
  947.     super= fMatKind;
  948.     (void) new DRadioButton(0,super,"Distance");
  949.     super->NextSubviewToRight();
  950.     (void) new DRadioButton(0,super,"Similarity");
  951.     fMatKind->SetValue(DSeqDoc::fgMatKind+1); 
  952.     super = this;
  953.     
  954.     fDistCor= new DCluster(cDistCor,super,0,0,false,"Comparison correction");
  955.     super= fDistCor;
  956.     (void) new DRadioButton(0,super,"none");
  957.     super->NextSubviewToRight();
  958.     (void) new DRadioButton(0,super,"Jukes");
  959.     super->NextSubviewToRight();
  960.     (void) new DRadioButton(0,super,"Olsen");
  961.     fDistCor->SetValue(DSeqDoc::fgDistCor+1); 
  962.     
  963.     super = this;
  964.     
  965.     //super->NextSubviewToRight();
  966.     //super->NextSubviewBelowLeft();
  967.  
  968.     this->AddOkayCancelButtons();
  969. }
  970.  
  971.  
  972. void DSeqDocPrefs::OkayAction() 
  973.     short             aSize, aStyle, aval;
  974.     char            name[256];
  975.     DMenu     *    aFontMenu, * aStyleMenu;
  976.     Nlm_FonT    aFont;
  977.     Boolean   newstyle;
  978.     
  979.     for (short imenu= 0; imenu<1; imenu++) {
  980.         
  981.         switch (imenu) {
  982.           case 0:
  983.                 aFontMenu= fSeqFontMenu; 
  984.                 aStyleMenu= fSeqStyleMenu; 
  985.                 aSize= fSeqSizeSw->GetValue();// aSize= gNameFontSize;
  986.                  
  987.                 aval= fCommonPctSw->GetValue();
  988.                 if (aval != DSeqList::gMinCommonPercent) {                
  989.                     DSeqList::gMinCommonPercent= aval;
  990.                     fNeedSave= true;
  991.                     }
  992.                     
  993.                 aval= fMinORFSw->GetValue();
  994.                 if (aval != DSeqList::gMinORFsize) {                
  995.                     DSeqList::gMinORFsize= aval;
  996.                     fNeedSave= true;
  997.                     }
  998.               break;
  999.           }
  1000.             
  1001.         if (aFontMenu && aFontMenu->GetFontChoice(name, sizeof(name))) {
  1002.         
  1003.             aStyle= 0;
  1004. #ifdef WIN_MAC
  1005.             if (!aStyleMenu->GetItemStatus(kStylePlain)) {
  1006.                 if (aStyleMenu->GetItemStatus(kStyleItalic   )) aStyle |= kItalic;
  1007.                 if (aStyleMenu->GetItemStatus(kStyleBold     )) aStyle |= kBold;
  1008.                 if (aStyleMenu->GetItemStatus(kStyleUnderline)) aStyle |= kUnderline;
  1009.                 }
  1010. #else
  1011.             short item= Nlm_GetValue(((DPopupMenu*)aStyleMenu)->fPopup);
  1012.             switch (item) {
  1013.                 case 1: aStyle= 0; break;
  1014.                 case 2: aStyle |= kItalic; break;
  1015.                 case 3: aStyle |= kBold; break;
  1016.                 case 4: aStyle |= kUnderline; break;
  1017.         }
  1018. #endif
  1019.              newstyle= aStyle != gSeqStyle;
  1020.              
  1021.             if (StringCmp(name,"System")==0) aFont= Nlm_systemFont;
  1022.             else if (StringCmp(name,"Program")==0) aFont= Nlm_programFont;
  1023.             else aFont= Nlm_GetFont( name, aSize, aStyle & kBold, aStyle & kItalic, 
  1024.                                                              aStyle & kUnderline, NULL);
  1025.             switch (imenu) {
  1026.               case 0: 
  1027.               if (newstyle || aSize != gSeqFontSize || StringCmp(name,gSeqFontName)!=0) {
  1028.                     if (gSeqFontName) MemFree(gSeqFontName);
  1029.                     gSeqFontName= StrDup(name);
  1030.                     gSeqFont= aFont;
  1031.                     gSeqFontSize= aSize;
  1032.                     gSeqStyle= aStyle;
  1033.                     fNeedSave= true;
  1034.                     }
  1035.                   break;
  1036.               }
  1037.               
  1038.             }
  1039.         }
  1040. }
  1041.  
  1042.  
  1043.  
  1044. Boolean DSeqDocPrefs::IsMyAction(DTaskMaster* action) 
  1045. {    
  1046.     DView* aview= (DView*) action;
  1047.     short result;
  1048.     
  1049.     switch (action->Id()) {
  1050.             // ?? handle stylemenu popup -- if plain selected, deselect others...
  1051.         //case kSeqStyleMenu:     break;
  1052.         //case cColored    : gColored= aview->GetStatus(); break;
  1053.         case cWriteMasks: DSeqFile::gWriteMasks= aview->GetStatus(); break;
  1054.         case cStartDoc  : DSeqDoc::fgStartDoc= aview->GetStatus(); break;
  1055.         case cMatKind        : DSeqDoc::fgMatKind= fMatKind->GetValue()-1; break;
  1056.         case cDistCor        : DSeqDoc::fgDistCor= fDistCor->GetValue()-1; break;
  1057.         default : return DWindow::IsMyAction(action);    
  1058.         }
  1059.         
  1060.     fNeedSave= true;
  1061.     return true;
  1062. }
  1063.  
  1064.  
  1065. void DSeqDocPrefs::Open()
  1066. {
  1067.     DWindow::Open();
  1068. }
  1069.  
  1070. void DSeqDocPrefs::Close()
  1071. {
  1072.     if (fNeedSave) {
  1073.         DSeqDocPrefs::SaveGlobals();
  1074.         fNeedSave= false;
  1075.         }
  1076.     DWindow::Close();
  1077. }
  1078.  
  1079.  
  1080.  
  1081.     // global calling function
  1082. void SeqDocPrefs(short id)
  1083. {
  1084.     switch (id) {
  1085.         case kSeqDocPrefInit: 
  1086.             DSeqDocPrefs::InitGlobals(); 
  1087.             break;
  1088.     
  1089.         case kSeqDocPrefDialog:
  1090.             if (!gSeqDocPrefs) {
  1091.                 gSeqDocPrefs = new DSeqDocPrefs();
  1092.                 gSeqDocPrefs->Initialize();
  1093.                 }
  1094.             if (gSeqDocPrefs && gSeqDocPrefs->PoseModally()) ;
  1095.             break;
  1096.     }
  1097.     
  1098. }
  1099.  
  1100.  
  1101.  
  1102. #if NETBLAST
  1103.  
  1104. ///class DBlastDialog : public DWindow 
  1105.  
  1106. class DBlastDialog : public DWindow {
  1107. public:
  1108.     enum { 
  1109.             kBlastDialogID = 29852,
  1110.             kStylePlain,kStyleItalic,kStyleBold,kStyleUnderline,
  1111.             cWriteMasks, cStartDoc, cColored
  1112.             };
  1113.     static char *gSeqFontName;
  1114.     static short gSeqFontSize;
  1115.     static short gSeqStyle;
  1116.     static Boolean gColored;
  1117.     static void InitGlobals();
  1118.     static void SaveGlobals();
  1119.  
  1120.     DPopupMenu  * fBlastDataMenu, 
  1121.                             * fBlastProgMenu;
  1122.     DSwitchBox    * fSeqSizeSw, * fCommonPctSw;
  1123.     Boolean             fNeedSave;
  1124.     short                fOldStyle;
  1125.     
  1126.     DBlastDialog();
  1127.     virtual ~DBlastDialog();
  1128.     virtual void Initialize();
  1129.     virtual void Open();
  1130.     virtual void Close();
  1131.     virtual void OkayAction();
  1132.     virtual Boolean IsMyAction(DTaskMaster* action); 
  1133.     virtual void NewFontCluster(char* title, DView* mainview,
  1134.                     DPopupMenu*& mfont, DPopupMenu*& mstyle, DSwitchBox*& swsize,
  1135.                     char* fontname, short fontstyle, short fontsize );
  1136. };
  1137.  
  1138. Global DBlastDialog* gSeqDocPrefs = NULL;
  1139. Global Nlm_FonT gSeqFont = NULL;
  1140.  
  1141. char* DBlastDialog::gSeqFontName = (char*) "times";
  1142. short 
  1143.             DBlastDialog::gSeqFontSize = 10, 
  1144.             DBlastDialog::gSeqStyle = 0; 
  1145. Boolean     
  1146.             DBlastDialog::gColored = true;
  1147.  
  1148. enum FonStyles { 
  1149.     kPlain = 0, kItalic = 1, kBold = 2, kUnderline = 4 
  1150.     };
  1151.  
  1152.  
  1153. DBlastDialog::DBlastDialog() :
  1154.     DWindow( 0, NULL, DWindow::fixed, -10, -10, -50, -20, "SeqDoc prefs", kDontFreeOnClose),
  1155.     fSeqFontMenu(NULL), fSeqStyleMenu(NULL), fSeqSizeSw(NULL), fCommonPctSw(NULL),
  1156.     fOldStyle(-1), fNeedSave(false)
  1157. {    
  1158. }
  1159.  
  1160. DBlastDialog::~DBlastDialog()
  1161. {
  1162. }
  1163.  
  1164.  
  1165. // static
  1166. void DBlastDialog::InitGlobals() 
  1167.     gSeqFontName= gApplication->GetPref( "gSeqFontName", "fonts", gSeqFontName);
  1168.     gSeqFontSize= gApplication->GetPrefVal( "gSeqFontSize", "fonts", "10");
  1169.     gSeqStyle= gApplication->GetPrefVal( "gSeqStyle", "fonts", "0");
  1170.     gSeqFont= ::GetAFont(gSeqFontName,gSeqFontSize, gSeqStyle);
  1171.  
  1172.     DSeqFile::gWriteMasks= gApplication->GetPrefVal( "gWriteMasks", "seqdoc", "1");
  1173.     DSeqDoc::fgStartDoc    = gApplication->GetPrefVal( "fgStartDoc", "seqdoc", "1");
  1174.     DSeqList::gMinCommonPercent= gApplication->GetPrefVal( "gMinCommonPercent", "seqdoc", "70");
  1175.     //gColored= gApplication->GetPrefVal( "gColored", "seqdoc","1");
  1176.  
  1177. }
  1178.  
  1179.  
  1180. //static
  1181. void DBlastDialog::SaveGlobals() 
  1182. {
  1183.     gApplication->SetPref( gSeqFontName, "gSeqFontName", "fonts");
  1184.     gApplication->SetPref( gSeqFontSize, "gSeqFontSize", "fonts");
  1185.     gApplication->SetPref( gSeqStyle, "gSeqStyle", "fonts");
  1186.     
  1187.     //gApplication->SetPref( gColored, "gColored", "seqdoc");
  1188.     gApplication->SetPref(  DSeqFile::gWriteMasks, "gWriteMasks", "seqdoc");
  1189.     gApplication->SetPref(  DSeqDoc::fgStartDoc, "fgStartDoc", "seqdoc");
  1190.     gApplication->SetPref(  DSeqList::gMinCommonPercent, "gMinCommonPercent", "seqdoc");
  1191. }
  1192.  
  1193.  
  1194.  
  1195.  
  1196.  
  1197. void DBlastDialog::Initialize() 
  1198.     DView* super;
  1199.     DCluster* clu;
  1200.     DCheckBox* ck;
  1201.  
  1202.     char* blastProgram = "blastn";
  1203.     char* blastDatabase = "nr";
  1204.     char* blastOptions = NULL;
  1205.     char* fastaInputFile = "spup-blast-input.fasta";
  1206.     char* outputFile = "spup-blast-result.text";
  1207.  
  1208.     super= this;
  1209.     
  1210.     new DPrompt( 0, super, "BLAST program", 0, 0, Nlm_programFont);             
  1211.     super->NextSubviewToRight();
  1212.         // fBlastProgMenu needs to be configurable from table file/prefs file
  1213.     fBlastProgMenu= new DPopupList( cBlastProg, super, true);
  1214.     super->NextSubviewBelowLeft();
  1215.     if (fSeq->IsAmino() {
  1216.           // protein query seq
  1217.       fBlastProgMenu->AddItem("blastp");
  1218.       fBlastProgMenu->AddItem("tblastn");
  1219.         }
  1220.     else {
  1221.             // nucleic query seq
  1222.       fBlastProgMenu->AddItem("blastn");
  1223.       fBlastProgMenu->AddItem("blastx");
  1224.       fBlastProgMenu->AddItem("tblastx");
  1225.       }
  1226.   fBlastProgMenu->SetValue(1); 
  1227.  
  1228.  
  1229.     new DPrompt( 0, super, "Nucleic databanks", 0, 0, Nlm_programFont);             
  1230.     super->NextSubviewToRight();
  1231.         // fDataMenu needs to be configurable from table file/prefs file
  1232.     fNucDataMenu= new DPopupList( cNucData, super, true);
  1233.     super->NextSubviewBelowLeft();
  1234.  
  1235.   fNucDataMenu->AddItem("nr");
  1236.   fNucDataMenu->AddItem("genbank");   
  1237.   fNucDataMenu->AddItem("gbupdate");  
  1238.   fNucDataMenu->AddItem("embl");  
  1239.   fNucDataMenu->AddItem("emblu");   
  1240.   fNucDataMenu->AddItem("pdb");  
  1241.   fNucDataMenu->AddItem("vector");  
  1242.   fNucDataMenu->AddItem("vector2");  
  1243.   fNucDataMenu->AddItem("dbest");  
  1244.   fNucDataMenu->AddItem("dbsts");  
  1245.   fNucDataMenu->AddItem("epd");  
  1246.   fNucDataMenu->AddItem("kabat");  
  1247.   fNucDataMenu->AddItem("hspest");  
  1248.   fNucDataMenu->AddSeparator();  
  1249.   fNucDataMenu->SetValue(1); 
  1250.  
  1251.     new DPrompt( 0, super, "Amino-acid databanks", 0, 0, Nlm_programFont);             
  1252.     super->NextSubviewToRight();
  1253.         // fDataMenu needs to be configurable from table file/prefs file
  1254.     fAminoDataMenu= new DPopupList( cAminoData, super, true);
  1255.     super->NextSubviewBelowLeft();
  1256.  
  1257.   fAminoDataMenu->AddItem("nr");
  1258.   fAminoDataMenu->AddItem("pdb");  
  1259.   fAminoDataMenu->AddItem("swissprot");  
  1260.   fAminoDataMenu->AddItem("spupdate");  
  1261.   fAminoDataMenu->AddItem("pir");  
  1262.   fAminoDataMenu->AddItem("genbank");  
  1263.   fAminoDataMenu->AddItem("gpupdate");  
  1264.   fAminoDataMenu->AddItem("tfd");  
  1265.   fAminoDataMenu->AddItem("kabat");  
  1266.   fAminoDataMenu->AddItem("hspnr");  
  1267.   fAminoDataMenu->AddItem("hspspdb");  
  1268.      
  1269.   fAminoDataMenu->SetValue(1); 
  1270.  
  1271. //////////////////////////////
  1272.     super= this;
  1273.     ck= new DCheckBox(cWriteMasks, super, "Save masks in file");
  1274.     ck->SetStatus(DSeqFile::gWriteMasks);
  1275.     super->NextSubviewBelowLeft();
  1276.  
  1277.     // check box for auto new document on startup ??
  1278.     ck= new DCheckBox(cStartDoc, super, "New align document on startup");
  1279.     ck->SetStatus(DSeqDoc::fgStartDoc);
  1280.     super->NextSubviewBelowLeft();
  1281.  
  1282.     new DPrompt( 0, super, "% common bases for consensus", 0, 0, Nlm_programFont);             
  1283.     super->NextSubviewToRight();
  1284.     fCommonPctSw = new DSwitchBox(0, super, true, true);
  1285.     fCommonPctSw->SetValues(DSeqList::gMinCommonPercent,100);
  1286.     super->NextSubviewBelowLeft();
  1287.     
  1288.     //ck= new DCheckBox(cColored, super, "Colored bases");
  1289.     //ck->SetStatus(gColored);
  1290.  
  1291.     super = this;
  1292.     //super->NextSubviewToRight();
  1293.     //super->NextSubviewBelowLeft();
  1294.  
  1295.     this->AddOkayCancelButtons();
  1296. }
  1297.  
  1298.  
  1299. void DBlastDialog::OkayAction() 
  1300.     short             aSize, aStyle, aCommon;
  1301.     char            name[256];
  1302.     DMenu     *    aFontMenu, * aStyleMenu;
  1303.     Nlm_FonT    aFont;
  1304.     Boolean   newstyle;
  1305.     
  1306.     for (short imenu= 0; imenu<1; imenu++) {
  1307.         
  1308.         switch (imenu) {
  1309.           case 0:
  1310.                 aFontMenu= fSeqFontMenu; 
  1311.                 aStyleMenu= fSeqStyleMenu; 
  1312.                 aSize= fSeqSizeSw->GetValue();// aSize= gNameFontSize;
  1313.                  
  1314.                 aCommon= fCommonPctSw->GetValue();
  1315.                 if (aCommon != DSeqList::gMinCommonPercent) {                
  1316.                     DSeqList::gMinCommonPercent= aCommon;
  1317.                     fNeedSave= true;
  1318.                     }
  1319.               break;
  1320.           }
  1321.             
  1322.         if (aFontMenu && aFontMenu->GetFontChoice(name, sizeof(name))) {
  1323.         
  1324.             aStyle= 0;
  1325.  
  1326.             short item= Nlm_GetValue(((DPopupMenu*)aStyleMenu)->fPopup);
  1327.             switch (item) {
  1328.                 case 1: aStyle= 0; break;
  1329.                 case 2: aStyle |= kItalic; break;
  1330.                 case 3: aStyle |= kBold; break;
  1331.                 case 4: aStyle |= kUnderline; break;
  1332.         }
  1333.              newstyle= aStyle != gSeqStyle;
  1334.              
  1335.             if (StringCmp(name,"System")==0) aFont= Nlm_systemFont;
  1336.             else if (StringCmp(name,"Program")==0) aFont= Nlm_programFont;
  1337.             else aFont= Nlm_GetFont( name, aSize, aStyle & kBold, aStyle & kItalic, 
  1338.                                                              aStyle & kUnderline, NULL);
  1339.             switch (imenu) {
  1340.               case 0: 
  1341.               if (newstyle || aSize != gSeqFontSize || StringCmp(name,gSeqFontName)!=0) {
  1342.                     if (gSeqFontName) MemFree(gSeqFontName);
  1343.                     gSeqFontName= StrDup(name);
  1344.                     gSeqFont= aFont;
  1345.                     gSeqFontSize= aSize;
  1346.                     gSeqStyle= aStyle;
  1347.                     fNeedSave= true;
  1348.                     }
  1349.                   break;
  1350.               }
  1351.               
  1352.             }
  1353.         }
  1354. }
  1355.  
  1356.  
  1357.  
  1358. Boolean DBlastDialog::IsMyAction(DTaskMaster* action) 
  1359. {    
  1360.     DView* aview= (DView*) action;
  1361.     
  1362.     switch (action->Id()) {
  1363.         //case cWriteMasks: DSeqFile::gWriteMasks= aview->GetStatus(); break;
  1364.         //case cStartDoc  : DSeqDoc::fgStartDoc= aview->GetStatus(); break;
  1365.         default : return DWindow::IsMyAction(action);    
  1366.         }
  1367.         
  1368.     fNeedSave= true;
  1369.     return true;
  1370. }
  1371.  
  1372.  
  1373. void DBlastDialog::Open()
  1374. {
  1375.     DWindow::Open();
  1376. }
  1377.  
  1378. void DBlastDialog::Close()
  1379. {
  1380.     if (fNeedSave) {
  1381.         DBlastDialog::SaveGlobals();
  1382.         fNeedSave= false;
  1383.         }
  1384.     DWindow::Close();
  1385. }
  1386.  
  1387.  
  1388.         
  1389. #endif
  1390.